import time
import socket

address = ('127.0.0.1', 8001)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(address)

total = 0

print('listening on %s:%s' % address)
n = 0

while True:
    data, addr = s.recvfrom(10)
    if not data:
        break
    l = len(data)
    total += l
    print('#', n, ', received', l, 'bytes from', addr)
    n += 1
    time.sleep(1)

s.close()
print('received %s bytes' % total)
